package com.jiangjiang.eshop.order.price.v1.factory;

import com.jiangjiang.eshop.common.constant.PromotionActivityType;
import com.jiangjiang.eshop.order.price.v1.calculator.FreightCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.PromotionActivityCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.TotalPriceCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.impl.*;
import com.jiangjiang.eshop.promotion.dto.PromotionActivityDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author Jianghaowen
 * @Date 2021/7/14
 * @Description: 折扣减免型订单金额计算工厂
 * @Version V1.0
 **/
@Component
public class DiscountOrderPriceCalculatorFactory implements OrderPriceCalculatorFactory {

    @Autowired
    private DefaultTotalPriceCalculator defaultTotalPriceCalculator;
    @Autowired
    private DefaultFreightCalculator defaultFreightCalculator;
    @Autowired
    private DefaultPromotionActivityCalculator defaultPromotionActivityCalculator;
    @Autowired
    private ReachDiscountPromotionActivityCalculator reachDiscountPromotionActivityCalculator;
    @Autowired
    private MultiDiscountPromotionActivityCalculator multiDiscountPromotionActivityCalculator;
    @Autowired
    private DirectDiscountPromotionActivityCalculator directDiscountPromotionActivityCalculator;





    @Override
    public TotalPriceCalculator createTotalPriceCalculator() {
        return defaultTotalPriceCalculator;
    }

    @Override
    public FreightCalculator createFreightCalculator() {
        return defaultFreightCalculator;
    }

    @Override
    public PromotionActivityCalculator createPromotionActivityCalculator(PromotionActivityDTO promotionActivity) {
        if(promotionActivity == null) {
            return defaultPromotionActivityCalculator;
        }

        Integer promotionActivityType = promotionActivity.getType();

        if(PromotionActivityType.REACH_DISCOUNT.equals(promotionActivityType)) {
            return reachDiscountPromotionActivityCalculator;
        } else if(PromotionActivityType.MULTI_DISCOUNT.equals(promotionActivityType)) {
            return multiDiscountPromotionActivityCalculator;
        } else if(PromotionActivityType.DIRECT_DISCOUNT.equals(promotionActivityType)) {
            return directDiscountPromotionActivityCalculator;
        }
        return defaultPromotionActivityCalculator;
    }
}
